﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace Projectkeuzemenu
{
    public partial class Projectkeuzemenu : Form
    {
        /*to do:
         * PARAMETERS GEBRUIKEN IN SQL
         */
        
        //waarden van de ingelogde persoon
        int userID;
        int projectAmount;

        //title en description voor home page
        string defaultTitle = "Welkom bij GrabCollab!";
        string defaultDescription = "Kies één van de projecten uit het menu om te beginnen";
        
        //hier komen title en description voor de projecten in
        //screw arrays we doen het oldschool
        string titel;
        string desc;
        string titel2;
        string desc2;
        string titel3;
        string desc3;
        string titel4;
        string desc4;
        string titel5;
        string desc5;

        //hier komen de project ID's in
        int[] projects = new int[4];
        
        //database gedoe
        MySqlConnection grabConnection = new MySqlConnection("Server=instance8003.db.xeround.com;Port=6006;Database=grabcollab;Uid=cookicom0;Pwd=pizzahut91;");
        MySqlDataReader reader = null;

        public Projectkeuzemenu()
        {

        }

        public Projectkeuzemenu(string name, string pass, int projectAmount, string title, string description, string title2, string description2, string title3, string description3, string title4, string description4, string title5, string description5)
        {
            string username = name;
            string password = pass;
            titel = title;
            desc = description;
            titel2 = title2;
            desc2 = description2;
            titel3 = title3;
            desc3 = description3;
            titel4 = title4;
            desc4 = description4;
            titel5 = title5;
            desc5 = description5;

            InitializeComponent();
            labelTitle.Text = defaultTitle;
            labelDescription.Text = defaultDescription;
            btnStart.Hide();

            switch (projectAmount)
            {
                case 1:
                    btnProject1.Show();
                    btnProject2.Hide();
                    btnProject3.Hide();
                    btnProject4.Hide();
                    btnProject5.Hide();
                    break;
                case 2:
                    btnProject1.Show();
                    btnProject2.Show();
                    btnProject3.Hide();
                    btnProject4.Hide();
                    btnProject5.Hide();
                    break;
                case 3:
                    btnProject1.Show();
                    btnProject2.Show();
                    btnProject3.Show();
                    btnProject4.Hide();
                    btnProject5.Hide();
                    break;
                case 4:
                    btnProject1.Show();
                    btnProject2.Show();
                    btnProject3.Show();
                    btnProject4.Show();
                    btnProject5.Hide();
                    break;
                case 5:
                    btnProject1.Show();
                    btnProject2.Show();
                    btnProject3.Show();
                    btnProject4.Show();
                    btnProject5.Show();
                    break;
            }

        }

        
        public Projectkeuzemenu(string name, string pass)
        {
            //hier moeten nog username en password afgevangen worden
            string username = name;
            string password = pass;
            
            //standaardwaarden displayen
            InitializeComponent();
            labelTitle.Text = defaultTitle;
            labelDescription.Text = defaultDescription;
            btnStart.Hide();
           
            try
            {
                grabConnection.Open();
                //userID ophalen
                MySqlCommand getID = new MySqlCommand("SELECT UserID FROM confirmed_users WHERE Email='" + username + "'", grabConnection);
                reader = getID.ExecuteReader();

                //userID ophalen
                while(reader.Read())
                {
                    userID = Convert.ToInt32(reader["userID"].ToString());
                }

                grabConnection.Close();

                grabConnection.Open();

                MySqlCommand getProjectAmount = new MySqlCommand("SELECT COUNT(UserID) AS AMOUNT FROM project_members WHERE UserID='"+userID+"'", grabConnection);
                reader = getProjectAmount.ExecuteReader();

                //aantal projecten ophalen
                while(reader.Read())
                {
                    projectAmount = Convert.ToInt32(reader["AMOUNT"].ToString());
                }

                grabConnection.Close();

                grabConnection.Open();

                MySqlCommand getProjectID = new MySqlCommand("SELECT ProjectID FROM project_members WHERE UserID='"+userID+"' ORDER BY ProjectID", grabConnection);
                reader = getProjectID.ExecuteReader();

                //userID ophalen
                int counter = 0;
                while (reader.Read())
                {
                    projects[counter] = Convert.ToInt32(reader["ProjectID"].ToString());
                    counter++;
                }

                grabConnection.Close();
            }
            catch (MySqlException)
            {
                MessageBox.Show("Sql error detected");
            }
            
            switch (projectAmount)
            {
                case 1:
                    btnProject1.Show();
                    btnProject2.Hide();
                    btnProject3.Hide();
                    btnProject4.Hide();
                    btnProject5.Hide();
                    break;
                case 2:
                    btnProject1.Show();
                    btnProject2.Show();
                    btnProject3.Hide();
                    btnProject4.Hide();
                    btnProject5.Hide();
                    break;
                case 3:
                    btnProject1.Show();
                    btnProject2.Show();
                    btnProject3.Show();
                    btnProject4.Hide();
                    btnProject5.Hide();
                    break;
                case 4:
                    btnProject1.Show();
                    btnProject2.Show();
                    btnProject3.Show();
                    btnProject4.Show();
                    btnProject5.Hide();
                    break;
                case 5:
                    btnProject1.Show();
                    btnProject2.Show();
                    btnProject3.Show();
                    btnProject4.Show();
                    btnProject5.Show();
                    break;
            }
        }

        private void btnHome_Click(object sender, EventArgs e)
        {
            labelTitle.Text = defaultTitle;
            labelDescription.Text = defaultDescription;
            btnStart.Hide();
        }

        private void btnProject1_Click(object sender, EventArgs e)
        {
        /*    try
            {
                //projecttitel en beschrijving ophalen
                grabConnection.Open();

                MySqlCommand getProjectInfo = new MySqlCommand("SELECT Projectnaam, Projectbeschrijving FROM projects WHERE ProjectID ='" + projects[0] + "'", grabConnection);
                reader = getProjectInfo.ExecuteReader();

                while (reader.Read())
                {
                    title = reader["Projectnaam"].ToString();
                    description = reader["Projectbeschrijving"].ToString();
                }
            }
            catch (MySqlException)
            {
                MessageBox.Show("Sql error detected! @ project 1");
            }

            grabConnection.Close();*/
            
            labelTitle.Text = titel;
            labelDescription.Text = desc;
            btnStart.Show();
        }

        private void btnProject2_Click(object sender, EventArgs e)
        {
          /*  try
            {
                //projecttitel en beschrijving ophalen
                grabConnection.Open();

                MySqlCommand getProjectInfo = new MySqlCommand("SELECT Projectnaam, Projectbeschrijving FROM projects WHERE ProjectID ='" + projects[1] + "'", grabConnection);
                reader = getProjectInfo.ExecuteReader();

                while (reader.Read())
                {
                    title = reader["Projectnaam"].ToString();
                    description = reader["Projectbeschrijving"].ToString();
                }
            }
            catch(MySqlException)
            {
                MessageBox.Show("Sql error detected! @ project 2");
            }
            
            grabConnection.Close();
            */
            labelTitle.Text = titel2;
            labelDescription.Text = desc2;
            btnStart.Show();
        }

        private void btnProject3_Click(object sender, EventArgs e)
        {
            /*try
            {
                //projecttitel en beschrijving ophalen
                grabConnection.Open();

                MySqlCommand getProjectInfo = new MySqlCommand("SELECT Projectnaam, Projectbeschrijving FROM projects WHERE ProjectID ='" + projects[2] + "'", grabConnection);
                reader = getProjectInfo.ExecuteReader();

                while (reader.Read())
                {
                    title = reader["Projectnaam"].ToString();
                    description = reader["Projectbeschrijving"].ToString();
                }
            }
            catch(MySqlException)
            {
                MessageBox.Show("Sql error detected! @ project 3");
            }

            grabConnection.Close();*/

            labelTitle.Text = titel3;
            labelDescription.Text = desc;
            btnStart.Show();
        }

        private void btnProject4_Click(object sender, EventArgs e)
        {
            /*try
            {
                //projecttitel en beschrijving ophalen
                grabConnection.Open();

                MySqlCommand getProjectInfo = new MySqlCommand("SELECT Projectnaam, Projectbeschrijving FROM projects WHERE ProjectID ='" + projects[3] + "'", grabConnection);
                reader = getProjectInfo.ExecuteReader();

                while (reader.Read())
                {
                    title = reader["Projectnaam"].ToString();
                    description = reader["Projectbeschrijving"].ToString();
                }
            }
            catch (MySqlException)
            {
                MessageBox.Show("Sql error detected! @ project 4");
            }

            grabConnection.Close();*/

            labelTitle.Text = titel4;
            labelDescription.Text = desc4;
            btnStart.Show();
        }

        private void btnProject5_Click(object sender, EventArgs e)
        {
           /* try
            {
                //projecttitel en beschrijving ophalen
                grabConnection.Open();

                MySqlCommand getProjectInfo = new MySqlCommand("SELECT Projectnaam, Projectbeschrijving FROM projects WHERE ProjectID ='" + projects[4] + "'", grabConnection);
                reader = getProjectInfo.ExecuteReader();

                while (reader.Read())
                {
                    title = reader["Projectnaam"].ToString();
                    description = reader["Projectbeschrijving"].ToString();
                }
            }
            catch (MySqlException)
            {
                MessageBox.Show("Sql error detected! @ project 5");
            }

            grabConnection.Close();*/
            
            labelTitle.Text = titel5;
            labelDescription.Text = desc5;
            btnStart.Show();
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            //GUI launchen met correcte variabelen
            this.Dispose(false);
            Gui.Interface gui = new Gui.Interface();
            gui.Show();
        }

        private void panelMain_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panelLogo_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
